package com.wx.plugin.config;

import com.wx.plugin.mp.core.WechatStandHandler;
import io.github.elkan1788.mpsdk4j.api.WechatAPI;
import io.github.elkan1788.mpsdk4j.api.WechatAPIImpl;
import io.github.elkan1788.mpsdk4j.core.WechatHandler;
import io.github.elkan1788.mpsdk4j.vo.MPAccount;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Component
@Data
@Configuration
public class MPConfig {

    @Value("${mp.mpid}")
    private String mpid;

    @Value("${mp.nickname}")
    private String nickname;

    @Value("${mp.appid}")
    private String appid;

    @Value("${mp.secret}")
    private String secret;

    @Value("${mp.channelToken}")
    private String channelToken;

    @Bean
    public MPAccount mpAccount(){
        MPAccount mpact = new MPAccount();
        // 修改为实际的公众号信息,可以在开发者栏目中查看
        mpact.setMpId(mpid);
        mpact.setNickName(nickname);
        mpact.setAppId(appid);
        mpact.setAppSecret(secret);
        mpact.setToken(channelToken);
//        mpact.setAESKey("******");
        return mpact;
    }

    @Bean
    public WechatHandler wechatHandler(){
        return new WechatStandHandler();
    }

    @Bean
    @Autowired
    public WechatAPI wechatAPI(MPAccount mpAccount){
        return WechatAPIImpl.create(mpAccount);
    }

}
